//
//  AAScaleExecutor.m
//  AnimAPI
//
//  Created by Alécio José Gomes Neto on 07/03/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "AAScaleExecutor.h"
#import <QuartzCore/CoreAnimation.h>


@implementation AAScaleExecutor

-(void) execute{
	[[view layer] removeAllAnimations];
	
	CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
	
	CATransform3D transform;
	NSValue *value;
	
	// To value
	transform = CATransform3DMakeScale(0.5f, 0.5f, 1.0f);
	value = [NSValue valueWithCATransform3D:transform];
	[scaleAnimation setToValue:value];
	
	// From value
	transform = CATransform3DMakeScale(1.0f, 1.0f, 1.0f);
	value = [NSValue valueWithCATransform3D:transform];
	[scaleAnimation setFromValue:value];
	
	[scaleAnimation setDuration: animation.animationTime];
    
    if (animation.flags & AA_AUTO_REVERSE) {
        [scaleAnimation setAutoreverses:YES];
    }

	// and its done
	[[view layer] addAnimation:scaleAnimation forKey:@"scale"];
}

@end
